﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Web;
using System.Threading;

namespace _8_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Thread thread;
        private void button1_Click(object sender, EventArgs e)
        {
            thread = new Thread(display);
            thread.IsBackground = true;
            thread.Start();
        }
        private void display()
        {
            string keywords = this.textBox1.Text.Trim();
            string url = "https://baike.baidu.com/item/" + keywords;
            string result = getInfo(url);
            Control.CheckForIllegalCrossThreadCalls = false;
            textBox2.Text = result;       
        }
        public string getInfo(string url)
        {
            string Info = null;
            try
            {
                WebRequest myRequest = WebRequest.Create(url);
                WebResponse myResponse = myRequest.GetResponse();
                Stream resStream = myResponse.GetResponseStream();
                StreamReader sr = new StreamReader(resStream);
                Info = sr.ReadToEnd();
                Info.Substring(0, 199);
                sr.Close();
                myResponse.Close();
            }
            catch (Exception) 
            {

            }
            return Info;
        }
    }
}